package com.icss.mqsp.db;

import com.ibatis.sqlmap.client.SqlMapClient;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class R1DBDataPrivoder
{
  private static Log log = LogFactory.getLog(R1DBDataPrivoder.class);
  private String systemName = "r1";
  
  public int insert(String sqlId, Map condition)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    int ret = 0;
    try
    {
      sqlMapClient.insert(sqlId, condition);
      ret = 1;
    }
    catch (SQLException e)
    {
      int ret1;
      log.error(e);
      ret1 = -1;
    }
    return ret;
  }
  
  public int delete(String sqlId, Map condition)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    int ret = 0;
    try
    {
      sqlMapClient.delete(sqlId, condition);
      ret = 1;
    }
    catch (SQLException e)
    {
      int ret1;
      e.printStackTrace();
      log.error(e);
      ret1 = -1;
    }
    return ret;
  }
  
  public int insert(String sqlId, Object object)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    int ret = 0;
    try
    {
      sqlMapClient.insert(sqlId, object);
      ret = 1;
    }
    catch (SQLException e)
    {
      int ret1;
      log.error(e);
      e.printStackTrace();
      ret1 = -1;
    }
    return ret;
  }
  
  public int update(String sqlId, Map condition)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    int ret = 0;
    try
    {
      sqlMapClient.update(sqlId, condition);
      ret = 1;
    }
    catch (SQLException e)
    {
      int ret1;
      log.error(e);
      ret1 = -1;
    }
    return ret;
  }
  
  public List query(String sqlId, Map condition)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    List list = null;
    try
    {
      list = sqlMapClient.queryForList(sqlId, condition);
    }
    catch (SQLException e)
    {
      e.printStackTrace();
      log.error(e);
    }
    return list;
  }
  
  public List query(String sqlId)
  {
    DBClient dbConnect = DBClient.getInstance();
    SqlMapClient sqlMapClient = dbConnect.getSqlMapClient(this.systemName);
    List list = null;
    try
    {
      list = sqlMapClient.queryForList(sqlId);
    }
    catch (SQLException e)
    {
      log.error(e);
    }
    return list;
  }
}
